package suncertify.launcher;

import suncertify.Server.ServerTest;
import suncertify.shared.DefaultConfig;
import suncertify.test.DBAccessTest;
import suncertify.ui.ClientTest;

/**
 *
 * @author jshah
 * Starts the Threads for RMI Server and Client GUI.
 * Reads the input argument from user and determines RMImode or standalone mode;
 */
public class ApplicationLauncher {

    /**
     * The argument CSR would enter to run the server side of the application
     */
    public static final String SERVERMODE = "server";
    /**
     * The argument CSR would enter to run the application in standalone mode
     */
    public static final String STANDALONE = "alone";
    /**
     * argument if the application should be run in RMI mode
     */
    public static final String RMIMODE = "rmi";
    /**
     * mode based on the value of this variable appropriate <code>ClientBroker</code> is called
     */
    public static String mode = STANDALONE;
    /**
     * mode to run the test 
     */
    public static final String TESTMODE = "test";

    /**
     * default constructor
     */
    public ApplicationLauncher(){
        
    }
    /**
     * Entry point of the application, starts the server thread and client thread, determines whether application should be run in local or Networked mode.expects a String input "server" to start Server, "alone" to stand the application in Stand Alone mode, "" no input starts application in
     * networked mode with RMI
     * @param args      input argument for the mode "alone" or "" for RMI
     */
    public static void main(String[] args) {


        
        if(args.length ==0 || args==null || args[0] == null){

            mode = RMIMODE;
            DefaultConfig.LOCALMODE = false;
            Thread configThread = new Thread(new ClientTest());
            configThread.start();
//
        }
        else if(args[0].equalsIgnoreCase(SERVERMODE))
        {
            mode = SERVERMODE;
            Thread serverThread = new Thread(new ServerTest());
            serverThread.start();
        }

        else if(args[0].equalsIgnoreCase(STANDALONE))
        {
            mode = STANDALONE;
            DefaultConfig.LOCALMODE = true;
            Thread csrThread = new Thread(new ClientTest());
            csrThread.start();
        }

        else if(args[0].equalsIgnoreCase(TESTMODE))
        {
            mode = TESTMODE;
            Thread test = new Thread(new DBAccessTest());
            test.start();
        }




    }
}
